<html>
<head><meta charset="utf-8"><title>Getting the Def of a Local from a Use · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20Def.20of.20a.20Local.20from.20a.20Use.html">Getting the Def of a Local from a Use</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238652582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20Def%20of%20a%20Local%20from%20a%20Use/near/238652582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20Def.20of.20a.20Local.20from.20a.20Use.html#238652582">(May 13 2021 at 17:25)</a>:</h4>
<p>Hi, I'm trying to understand the liveness stuff in MIR. I'd like to find the original initialization of a local when looking at some arbitrary use of it. For example:</p>
<div class="codehilite"><pre><span></span><code>let x = Vec::new();
... // bunch of other stuff
use(x)
</code></pre></div>
<p>If I'm looking at the MIR statement for <code>use(x)</code>, I want to find where <code>x</code> was originally initialized (i.e. line 1). In MIR, a bunch of intermediate <code>dest = move src;</code> statements can get created and it's kinda difficult to chase them backward to the original use. I'm guessing this is what the liveness stuff does, but I have no idea where to start with it. Is what I'm trying to do possible in MIR?</p>
<p>I'm new to this part of the compiler, so sorry if terminology is wrong / badly explained.</p>



<a name="238653036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20Def%20of%20a%20Local%20from%20a%20Use/near/238653036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20Def.20of.20a.20Local.20from.20a.20Use.html#238653036">(May 13 2021 at 17:28)</a>:</h4>
<p>sounds like you're looking for the "reaching definitions" dataflow analysis</p>



<a name="238653070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20Def%20of%20a%20Local%20from%20a%20Use/near/238653070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20Def.20of.20a.20Local.20from.20a.20Use.html#238653070">(May 13 2021 at 17:29)</a>:</h4>
<p>I don't think it's currently implemented though</p>



<a name="238653466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20Def%20of%20a%20Local%20from%20a%20Use/near/238653466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20Def.20of.20a.20Local.20from.20a.20Use.html#238653466">(May 13 2021 at 17:32)</a>:</h4>
<p>Ah, that sounds like what I'm after yeah.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>